package cn.dkk.create_design.prototype.shallow_clone_prototype;

import cn.dkk.create_design.factory.pojo.parent.Coffee;

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Coffee coffee = new Coffee() {
            @Override
            public String getName() {
                return "咖啡的内部方法";
            }
        };

        ShallowClonePrototype shallowClonePrototype = new ShallowClonePrototype(coffee);
        ShallowClonePrototype clone = shallowClonePrototype.clone();
        // 浅克隆的对象依然是新对象 false
        System.out.println(clone==shallowClonePrototype);
        // 浅克隆对象的成员变量引用指向元对象的引用 true
        System.out.println(clone.getCoffee()==shallowClonePrototype.getCoffee());
    }
}
